package com.visikard.business;

import android.util.Log;

import com.visikard.application.Constant;
import com.visikard.net.VKregisterNetworkException;
import com.visikard.request.GiftKardRequest;
import com.visikard.response.BaseResponse;
import com.visikard.response.GetGiftKardResponse;
import com.visikard.response.RingUpResponse;

public class GiftKardBUS {

	public RingUpResponse ringUp(final long merchantId, final long staffId, final long uid, final long transactionId,
			final long storeId, final String amountRedeemed, final String previousBalance, final int isGiftKard,
			final String redeemAddress) {

		GiftKardRequest ar = new GiftKardRequest();
		RingUpResponse result = new RingUpResponse();

		try {
			String response = ar.ringUp(merchantId, staffId, uid, transactionId, storeId, amountRedeemed,
					previousBalance, isGiftKard, redeemAddress);
			result.extractDataFromServer(response);
		}
		catch (VKregisterNetworkException e) {
			Log.e(Constant.LOG_TAG, "getGiftKardList: " + e.getMessage());
			result.setErrorCode(BaseResponse.NETWORK_ERROR);
			result.setErrorMsg(e.getMessage());
		}
		catch (Exception e) {
			Log.e(Constant.LOG_TAG, "getGiftKardList: " + e.getMessage());
			result.setErrorCode(BaseResponse.UNKNOWN_ERROR);
			result.setErrorMsg(e.getMessage());
		}

		return result;
	}

	public GetGiftKardResponse getGiftKardList(long merchantId, String redeemCode) {

		GiftKardRequest ar = new GiftKardRequest();
		GetGiftKardResponse result = new GetGiftKardResponse();

		try {
			String response = ar.getGiftKard(merchantId, redeemCode);
			result.extractDataFromServer(response);
		}
		catch (VKregisterNetworkException e) {
			Log.e(Constant.LOG_TAG, "getGiftKardList: " + e.getMessage());
			result.setErrorCode(BaseResponse.NETWORK_ERROR);
			result.setErrorMsg(e.getMessage());
		}
		catch (Exception e) {
			Log.e(Constant.LOG_TAG, "getGiftKardList: " + e.getMessage());
			result.setErrorCode(BaseResponse.UNKNOWN_ERROR);
			result.setErrorMsg(e.getMessage());
		}
		return result;
	}

}
